'''
Author: caishuyang
Date: 2022-11-25 14:49:37
LastEditors: caishuyang
LastEditTime: 2023-01-02 16:39:50
Description: 
'''
#将js标签转换为数据集，存放于Dataset下，在visual_ws下运行

import os,glob

#规范命名
Paths = glob.glob(os.path.join('Oridata','*.*'))
for Path in Paths:
    NewPath=Path.replace(' ','')
    os.rename(Path,NewPath)

LabelPaths = glob.glob(os.path.join('Oridata','*.json')) #'../Oridata/*.json'
DataTrain=os.path.join('Dataset','Train','')
if not os.path.exists(DataTrain):
	os.makedirs(DataTrain, exist_ok=DataTrain)

#转换为数据集
for LabelPath in LabelPaths:
	print(LabelPath)
	Name = os.path.basename(LabelPath).split('.')[0]	
	cmd = 'labelme_json_to_dataset '+LabelPath+' -o '+DataTrain+Name
	os.system(cmd)